package ar.com.spsolutions.splilabrary.view.pages.book;

/**
 * 
 */
import org.apache.wicket.PageReference;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebPage;

import ar.com.spsolutions.splibrary.book.Book;
import ar.com.spsolutions.splibrary.notifiers.MockNotifier;

/**
 * @author Matej Knopp
 * 
 */
public class LoanModalWindow extends WebPage {

	private static final long serialVersionUID = 9051525399754148766L;

	/**
	 * 
	 * @param modalWindowPage
	 * @param window
	 */
	public LoanModalWindow(final PageReference modalWindowPage,
			final ModalWindow window) {
		super();
		this.add(new AjaxLink<Void>("closeOK") {
			private static final long serialVersionUID = -5594537591280373946L;

			@Override
			public void onClick(final AjaxRequestTarget target) {
				final Book book = BookDetail.getReserveBook();
				book.setNotifier(new MockNotifier());
				book.reservedFor(BookDetail.getReserveUser());
				BookDetail.getBookService().update(book);
				window.close(target);
			}
		});

		this.add(new AjaxLink<Void>("closeCancel") {
			private static final long serialVersionUID = 2235484738855927511L;

			@Override
			public void onClick(final AjaxRequestTarget target) {
				window.close(target);
			}
		});

	}
}
